//
//  IconButton.h
//  OCDemo
//
//  Created by zhumuzhi on 2021/12/13.
//

#import <UIKit/UIKit.h>

#define UIEdgeOffsetsZero UIEdgeOffsetsMake(0, 0, 0, 0)

typedef NS_ENUM (NSUInteger, IconStyle) {
    IconStyleLeft = 1,
    IconStyleRight,
    IconStyleCenter,
    IconStyleTop,
    IconStyleBottom
};

typedef struct UIEdgeOffsets
{
    CGFloat left, top, width, height;
} UIEdgeOffsets;

static inline UIEdgeOffsets UIEdgeOffsetsMake(CGFloat left, CGFloat top, CGFloat width, CGFloat height)
{
    UIEdgeOffsets offsets = {left, top, width, height};
    return offsets;
}

static inline CGRect UIEdgeOffsetsRect(CGRect rect, UIEdgeOffsets offsets)
{
    rect.origin.x    += offsets.left;
    rect.origin.y    += offsets.top;
    rect.size.width  += offsets.width;
    rect.size.height += offsets.height;
    return rect;
}

NS_ASSUME_NONNULL_BEGIN

@interface IconButton : UIButton

@property (nonatomic) IconStyle         iconStyle;
@property (nonatomic) UIEdgeOffsets     imageEdgeOffsets;              // default is UIEdgeOffsetsZero
@property (nonatomic) UIEdgeOffsets     titleEdgeOffsets;              // default is UIEdgeOffsetsZero

- (instancetype)initWithFrame:(CGRect)frame style:(IconStyle)style;

@end

NS_ASSUME_NONNULL_END
